package Day28;

import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-10-21
 * Time: 14:38
 * To BE A Better Person-2020-3-2
 */
class ListNode{

   public static class Node{
        int val;
        Node next;
        public Node(int val){
            this.val=val;
        }
    }
    public Node head;

   public void add(int val){
       Node node=new Node(val);
       if(head == null){
           head=node;
       }else{
           Node cur=head;
           while(cur.next != null){
               cur=cur.next;
           }
           cur.next=node;
       }
   }

   public void revers(int beg,int end){
       Stack<Node> s=new Stack<>();
       if(head.next == null) return ;
       Node cur = head;
       Node bef = head;
       int index=1;
       while(index < beg){
           bef=cur;
            cur = cur.next;
            index++;
       }
       Node temp = bef;
       //将区间内的节点放入栈中
       while(index <= end){
           s.push(cur);
           cur=cur.next;
           index++;
       }
       cur=cur.next;
       //再一个个弹出来
       while(!s.empty()){
           temp.next=s.pop();
           temp=temp.next;
       }
       temp.next=cur;
       //return head;
   }
    public void display(){
        Node cur=this.head;
        while(cur != null){
            System.out.print(cur.val+" ");
            cur=cur.next;
        }
    }


}
public class TestDemo1 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        ListNode listNode=new ListNode();
        int num=sc.nextInt();
        int beg,end;
        for (int i = 0; i < num; i++) {
            listNode.add(sc.nextInt());
        }
        beg=sc.nextInt();
        end=sc.nextInt();
        listNode.revers(beg,end);
        listNode.display();
    }
}
